# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class Dock(QMainWindow):
    def __init__(self):
        super(Dock, self).__init__()

        layout = QHBoxLayout()
        # 实例化主窗口的QMenuBar对象
        bar = self.menuBar()
        # 向菜单栏中添加新的QMenu对象，父菜单
        file = bar.addMenu("File")
        # 添加子窗口
        file.addAction("New")
        save = QAction("Save", self)
        # 字符串写法固定，不能出现空格("Ctrl+ S")
        save.setShortcut("Ctrl+S")
        file.addAction(save)
        quit = QAction("Quit", self)
        file.addAction(quit)

        self.items = QDockWidget("Dockable",self)
        self.listWidget = QListWidget()
        self.listWidget.addItem("item1")
        self.listWidget.addItem("item2")
        self.listWidget.addItem("item3")
        # 设置窗口区域
        self.items.setWidget(self.listWidget)
        # 是否可以浮动
        self.items.setFloating(False)
        # 设置QTextEdit为中央小控件
        self.setCentralWidget(QTextEdit())
        # 将窗口放置在中央小控件的右侧
        self.addDockWidget(Qt.RightDockWidgetArea,self.items)
        self.setLayout(layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dock = Dock()
    dock.show()
    sys.exit(app.exec_())